package com.inspur.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.inspur.system.dto.PmFlawDTO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.inspur.common.annotation.Log;
import com.inspur.common.core.controller.BaseController;
import com.inspur.common.core.domain.AjaxResult;
import com.inspur.common.enums.BusinessType;
import com.inspur.system.domain.PmFlaw;
import com.inspur.system.service.IPmFlawService;
import com.inspur.common.utils.poi.ExcelUtil;
import com.inspur.common.core.page.TableDataInfo;

/**
 * 缺陷Controller
 * 
 * @author ruoyi
 * @date 2024-04-08
 */
@RestController
@RequestMapping("/system/flaw")
public class PmFlawController extends BaseController
{
    @Autowired
    private IPmFlawService pmFlawService;

    /**
     * 查询缺陷列表
     */
    @PreAuthorize("@ss.hasPermi('system:flaw:list')")
    @GetMapping("/list")
    public TableDataInfo list(PmFlawDTO pmFlaw)
    {
        startPage();
        List<PmFlawDTO> list = pmFlawService.selectPmDTOFlawList(pmFlaw);
        return getDataTable(list);
    }

    /**
     * 查询缺陷数量
     */
    @PreAuthorize("@ss.hasPermi('system:flaw:listnum')")
    @GetMapping("/listNum")
    public AjaxResult listNum()
    {
        return success(pmFlawService.selectPmFlawNum());
    }

    /**
     * 导出缺陷列表
     */
    @PreAuthorize("@ss.hasPermi('system:flaw:export')")
    @Log(title = "缺陷", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PmFlaw pmFlaw)
    {
        List<PmFlaw> list = pmFlawService.selectPmFlawList(pmFlaw);
        ExcelUtil<PmFlaw> util = new ExcelUtil<PmFlaw>(PmFlaw.class);
        util.exportExcel(response, list, "缺陷数据");
    }

    /**
     * 获取缺陷详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:flaw:query')")
    @GetMapping(value = "/{cFlawNo}")
    public AjaxResult getInfo(@PathVariable("cFlawNo") String cFlawNo)
    {
        return success(pmFlawService.selectPmFlawByCFlawNo(cFlawNo));
    }

    /**
     * 新增缺陷
     */
    @PreAuthorize("@ss.hasPermi('system:flaw:add')")
    @Log(title = "新增缺陷", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PmFlaw pmFlaw)
    {
        return toAjax(pmFlawService.insertPmFlaw(pmFlaw));
    }

    /**
     * 修改缺陷
     */
    @PreAuthorize("@ss.hasPermi('system:flaw:edit')")
    @Log(title = "修改缺陷", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PmFlaw pmFlaw)
    {
        return toAjax(pmFlawService.updatePmFlaw(pmFlaw));
    }

    /**
     * 删除缺陷
     */
    @PreAuthorize("@ss.hasPermi('system:flaw:remove')")
    @Log(title = "删除缺陷", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cFlawNos}")
    public AjaxResult remove(@PathVariable String[] cFlawNos)
    {
        return toAjax(pmFlawService.deletePmFlawByCFlawNos(cFlawNos));
    }
}
